﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using foursquare.Foursquare;

namespace foursquare.Forms
{
    public partial class UserView : Form
    {
        int rowHeight = 14;

        public UserView(string uid)
        {
            InitializeComponent();

            User u;

            if (!String.IsNullOrEmpty(uid))
            {
                u = FS.GetUser(Convert.ToInt32(uid), 0, 0);
            }
            else
            {
                u = FS.GetSelf();
            }

            pnlMain.Width = this.ClientRectangle.Width;
            
            pnlMain.Controls.Add(LabelControl(u.firstname + " " + u.lastname));
            pnlMain.Controls.Add(LabelControl(u.phone));
            pnlMain.Controls.Add(LabelControl(u.email));
            PictureBox photo = new PictureBox();
            photo.Image = FS.GetUserPhoto(u);
            photo.Height = 75;
            photo.Width = 75;
            photo.Dock = DockStyle.Bottom;
            pnlMain.Controls.Add(photo);

            if (String.IsNullOrEmpty(uid))
            {
                List<Checkin> checkins = FS.GetHistory();
                foreach (Checkin c in checkins)
                {
                    CheckinPanel cp = new CheckinPanel(c);
                    cp.Dock = DockStyle.Bottom;
                    pnlMain.Controls.Add(cp);
                }
            }

            pnlMain.Height = rowHeight * (pnlMain.Controls.Count - 1) + 75;
        }

        private Label LabelControl(string text)
        {
            Rectangle rect = this.ClientRectangle;

            Label lbl = new Label();
            lbl.Text = text;
            lbl.Width = this.ClientRectangle.Width;
            rowHeight = (int)CFMeasureString.MeasureString(lbl, lbl.Text, rect).Height;
            lbl.Height = rowHeight;
            lbl.Dock = DockStyle.Bottom;
            return lbl;
        }
    }
}